package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 新增地址
     *
     * @param addressBook
     */
    void insert(AddressBook addressBook);

    /**
     * 根据条件查询地址列表
     *
     * @param addressBook
     * @return
     */
    List<AddressBook> listAddressBook(AddressBook addressBook);

    /**
     * 根据Id修改地址
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 根据Id查询地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook selectById(Long id);

    /**
     * 根据Id删除地址
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据用户id更新地址为非默认
     * @param addressBook
     */
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);
}
